# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=cargo-c
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.15
pkgrel=2
pkgdesc='A cargo subcommand to build and install C-ABI compatibile dynamic and static libraries (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang32' 'clang64' 'clangarm64')
url='https://github.com/lu-zero/cargo-c/'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-libgit2"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/lu-zero/cargo-c/archive/v${pkgver}.tar.gz"
        "${_realname}-${pkgver}.Cargo.lock"::"https://github.com/lu-zero/cargo-c/releases/download/v${pkgver}/Cargo.lock"
        001-add-lib-prefix-on-windows-gnu.patch
        002-accept-windows-gnu-aarch64.patch)
sha256sums=('ba29e662c2419ce12e4d5a9d0b05c057378088f474bc9316238c0a621b488299'
            '90453e28af7052126f3f452061ba667e2cf52dcd0b2c76bb900fb4b60ddd2d91'
            '80b0e0d5713d5eb74b62433386642ee87daeab8952dbbbb3ad4b54a4f53a4c6d'
            '7c056b2110fbc8a3ce05739797185a60cbb7cf575cb26387ad13b0fe35a61039')

prepare() {
    cp "${srcdir}/${_realname}-${pkgver}.Cargo.lock" "${_realname}-${pkgver}/Cargo.lock"
    cd "${srcdir}/${_realname}-${pkgver}"

    patch -p1 -i "${srcdir}"/001-add-lib-prefix-on-windows-gnu.patch
    patch -p1 -i "${srcdir}"/002-accept-windows-gnu-aarch64.patch

    cargo fetch \
        --locked
}

build() {
    cd "${srcdir}/${_realname}-${pkgver}"

    cargo build \
        --release \
        --frozen \
        --offline
}

check() {
    cd "${srcdir}/${_realname}-${pkgver}"

    cargo test \
        --release \
        --frozen
}

package() {
    cd "${srcdir}/${_realname}-${pkgver}"

    cargo install \
    --frozen \
    --offline \
    --no-track \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

    install -D -m644 "LICENSE" -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
